package com.example.stock.business.monitor.logic;

import com.example.stock.excel.Monitor;
import com.example.stock.model.MonthDetail;
import com.example.stock.service.MonthDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 找出连续下跌有股票
 */
@Component
public class MonthDecreaseCountMonitor implements Trigger{

    @Autowired
    MonthDataService monthDataService;

    @Override
    public boolean trigger(Monitor monitor) {
        // 获取给定股票的月份细节数据
        List<MonthDetail> monthRawData = monthDataService.getMonthRawData(monitor.getStock());

        int dataSize = monthRawData.size(); // 总数据点数量
        int startIndex = Math.max(0, dataSize - Integer.parseInt(monitor.getExtra())); // 计算开始索引，包括extra数量

        // 获取子列表，用于进一步检查
        List<MonthDetail> subList = monthRawData.subList(startIndex, dataSize);

        // 检查子列表中的月份细节百分比是否都小于或等于零
        for (MonthDetail monthDetail : subList) {
            if (monthDetail.getMonthPct() > 0.0) {
                return false; // 如果有任何正的增长百分比，则触发条件不满足
            }
        }
        return true; // 所有月份细节百分比都小于或等于零时，触发条件满足
    }
}
